package com.cefa.edu.controller;

import com.cefa.edu.common.result.FailureResult;
import com.cefa.edu.common.result.Result;
import com.cefa.edu.common.result.ReturnMessage;
import com.cefa.edu.common.result.SuccessResult;
import com.cefa.edu.model.ClassInfo;
import com.cefa.edu.service.AuthService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.websocket.server.PathParam;
import java.util.List;

@RestController
@RequestMapping("auth")
public class AuthController {
    private static final Logger logger=LoggerFactory.getLogger(AuthController.class);

    @Autowired
    AuthService authService;

    @RequestMapping(path = "findAuthClass/{userid}", method = RequestMethod.GET)
    @CrossOrigin
    public Result<List<ClassInfo>> getAuthClass(@PathParam("userid") Integer userid) {

        try{
            List<ClassInfo> authClass = authService.getAuthClass(userid);
            return new SuccessResult<>(new ReturnMessage("200", "success"), authClass);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return new FailureResult<>(new ReturnMessage("500", e.getMessage()));
        }
    }
}

